<?php
class ControllerModuleReviews extends Controller {
	protected function index($setting) {
		if (isset($setting['showTitle'])){
			$this->data['showTitle'] = $setting['showTitle'];
		}else{
			$this->data['showTitle'] = 0;//show
		}
		if (isset($setting['showType'])){
			$this->data['showType'] = $setting['showType'];
		}else{
			$this->data['showType'] = 0;//single
		}
		
		$this->language->load('module/reviews');
		$this->data['heading_title'] = $this->language->get('heading_title');
		$this->data['text_author'] = $this->language->get('text_author');
		$this->data['text_addTime'] = $this->language->get('text_addTime');
		$this->data['text_review'] = $this->language->get('text_review');
		
		$this->load->model('tool/image');
		
		$this->load->model('catalog/review');
		$results = $this->model_catalog_review->getReviewsForHome($setting['limit']);
		$this->data['reviews'] = array();	
		foreach ($results as $result) {
			$this->data['reviews'][] = array(
				'author'        => utf8_substr($result['author'], 0, 3) . '***',
				'content'       => utf8_substr($result['text'], 0, 50) . '...',
				'rating'        => $result['rating'],
				'date_added'    => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
				'product_id'    => $result['product_id'],
				'image'         => $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']),
				'name'          => $result['name'],
				'href'    	    => $this->url->linkRewrite(ROUTE_REVIEWS_R, $result['name'] . '_p' . $result['product_id']),
			);
		}
		
		$this->data['text_more_reviews'] = $this->language->get('text_more_reviews');
		$this->data['text_more_reviews_link'] = $this->url->linkRewrite(ROUTE_REVIEWS_R);
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/reviews.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/module/reviews.tpl';
		} else {
			$this->template = 'default/template/module/reviews.tpl';
		}

		$this->render();
	}
}
?>